# Contributor: Will Sinatra <wpsinatra@gmail.com>
# Maintainer: Will Sinatra <wpsinatra@gmail.com>
pkgname=aws-session-manager-plugin
pkgver=1.2.553.0
pkgrel=0
pkgdesc="AWS Session Manager Plugin for aws-cli."
url="https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-working-with-install-plugin.html"
license="Apache-2.0"
arch="" # blocked by aws-cli
#arch="x86_64 aarch64"
# aws-cli is not packaged on the following arches due to missing dependency py3-awscrt
# armhf, armv7, s390x, ppc64le
# aws-cli is not packaged on the following arches due to compilation issues
# x86
depends="aws-cli amazon-ssm-agent"
makedepends="go gcompat"
source="$pkgname-$pkgver.tar.gz::https://github.com/aws/session-manager-plugin/archive/refs/tags/$pkgver.tar.gz
	001_correct_makefile.patch
	ssmcli.initd
	session-manager-plugin.initd"
options="!check"
builddir="$srcdir/session-manager-plugin-$pkgver"
subpackages="$pkgname-openrc"

case "$CARCH" in
	armhf) build_arch=arm ;;
	armv7) build_arch=arm ;;
	x86) build_arch=x86 ;;
	x86_64) build_arch=amd64 ;;
	aarch64) build_arch=arm64 ;;
esac

build() {
	make build-linux-$build_arch
}

package() {
	#ssmcli
	install -Dm0755 "$builddir"/bin/linux_$build_arch/ssmcli -t "$pkgdir"/usr/bin/
	install -Dm0644 "$builddir"/bin/seelog_unix.xml -t "$pkgdir"/etc/amazon/ssmcli/seelog.xml

	#session-manager-plugin
	install -Dm0755 "$builddir"/bin/linux_${build_arch}_plugin/session-manager-plugin -t "$pkgdir"/usr/bin/
	install -Dm0644 "$builddir"/bin/seelog_unix.xml -t "$pkgdir"/etc/amazon/sessionmanagerplugin/seelog.xml
	install -Dm0644 "$builddir"/bin/seelog_windows.xml.template -t "$pkgdir"/etc/amazon/sessionmanagerplugin/

	install -Dm0755 "$srcdir"/session-manager-plugin.initd -t "$pkgdir"/etc/init.d/session-manager-plugin
	install -Dm0755 "$srcdir"/ssmcli.initd -t "$pkgdir"/etc/init.d/ssmcli
}

sha512sums="
49d4715adfce526376bd4f4d2cf136779aff0912e904f7158a8dc3e163f77afbf43511358cb3e17587d16d2f81a55fae007ed8f04d144e513948f2b7878a2e45  aws-session-manager-plugin-1.2.553.0.tar.gz
61df1f326d0963f8b81ccef56e87b907eff57cb98ecfb3839a61d008157bdcf8180609fdc23b75ad01cf3c7a99d89cd50e52f48c9b0c42144a166f27738394a4  001_correct_makefile.patch
5e08d65a18117bcf821fea79ae03c69063196c116864ae7261ab58a07000c3dc04d53cdab50a47461ab2b08421f0d63a4c349d91d05223634cc8e4f1af8bca74  ssmcli.initd
c0c9a0f24005b0c0c609a82b7754f41a5511a730d6cf5a74f01c427596c5e676f9a96077cb917530ded49dca06a916cde62152f006a3856f9313d7681dc6ebf5  session-manager-plugin.initd
"
